package com.vc.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vc.common.api.ApiResult;
import com.vc.model.entity.BmsBillboard;
import com.vc.service.BmsBillboardService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/billboard")
public class BmsBillboardController extends BaseController {

    @Resource
    private BmsBillboardService bmsBillboardService;

    // 查询公告板
    @GetMapping("/show")
    public ApiResult<BmsBillboard> getNotices() {
        // 对应mybatis plus写法 创一个LambdaQueryWrapper的对象 给一个 查出所有状态为true的公告 的条件
        List<BmsBillboard> list = bmsBillboardService.list(new
                LambdaQueryWrapper<BmsBillboard>().eq(BmsBillboard::isShows, true));

        // 返回列表里的最后一条记录
        return ApiResult.success(list.get(list.size() - 1));
    }
}
